<!DOCTYPE html  >
<html lang="en" xmlns:th="http://www.thymeleaf.org">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <link rel="stylesheet" href="/erp/css/style.css"/>
        <link rel="stylesheet" href="/erp/assets/css/ace.min.css"/>
        <link rel="stylesheet" href="/erp/assets/css/font-awesome.min.css"/>

        <script th:src="@{/erp/js/jquery-1.9.1.min.js}"></script>
        <script type="text/javascript" th:src="@{/erp/js/jquery.SuperSlide.2.1.js}"></script>
        <script th:src="@{/erp/assets/layer/layer.js}" type="text/javascript"></script>

        <title>注册</title>
    </head>
    <body style="padding-left: 200px">
        <div class="margin clearfix">
            <div class="stystems_style">
            </div>
        </div>
        <form id="regiest_form">
            <div id="newdropdown" class="tab-pane active">
                <h4 class="header blue lighter bigger">
                    <i class="icon-coffee green"></i>
                    填写企业用户信息
                </h4>
                <ul>
                    <label>企业名称：</label><input class="width-20" name="companyName" type="text" id="companyName"/></span>
                    <span style="color: red;">*</span>必填信息</br></br>
                    <label>企业法人：</label><input class="width-20" name="companyLegalPerson" type="text"
                                               id="companyLegalPerson"/><span id="msg2"></span><span
                        style="color: red;">*</span>必填信息<br></br>
                    <label>登录账号：</label><input class="width-20" name="useraccount" type="text" id="useraccount"/><span
                        id="msg3"></span><span style="color: red;">*</span>必填信息<br></br>
                    <label>登录密码：</label><input class="width-20" name="password" type="password" id="userpwd"/><span
                        id="msg4"></span><span style="color: red;">*</span>必填信息<br></br>
                    <label>确认密码：</label><input class="width-20" name="password1" type="password" id="password1"/><span
                        id="msg5"></span><span style="color: red;">*</span>必填信息<br></br>
                    <label>联系方式：</label><input class="width-20" name="companyTel" type="text" id="companyTel"/><span
                        id="msg6"></span><span style="color: red;">*</span>必填信息<br></br>
                    <ul class="search_content clearfix">
                        <li><label class="l_f" id="area">公司地址：</label><input class="width-20" name="companyAddress"
                                                                             type="hidden" id="address"/><span
                                id="msg7"></span><span id="address1" class="formControls col-4" style="width:115px">*必填信息<br>
		  </span></li>
                    </ul>
                    <br/>
                    <label>企业邮箱：</label><input class="width-20" name="companyEmail" type="text" id="companyEmail"/>
                    <span id="msg8"></span><span style="color: red;">*</span>必填信息<br></br>
                    <label class="l_f">经营范围：</label><span class="formControls col-4" style="width:115px"><span
                        id="msg9"></span>
		  <select style=" width:360px" class="form-control" name="companyRange" id="companyRange">
          <option value="-1">选择省份</option>
              <tr th:each="Provinces : ${Provinces}">
                <option th:value="${Provinces.province}" th:text="${Provinces.province}">河南省</option>
              </tr>
              <!--<option value="河北省">河北省</option>
              <option value="湖北省">湖北省</option>-->
          </select>
		  </span></br>
                </ul>
                <div></br></br>
                    <td class="tl">
                        <span class="E-checked"><input type="checkbox" name="MemberRegister1$ctl00$CheckBoxIfAgree"
                                                       checked="checked"/></span>同意
                        <a href='register_xy.html' target="_blank" class="blue">《用户注册协议》</a>
                        <span id="spanIfAgree" visible="false"></span>
                    </td>
                </div>
                </br>
                <div class="clearfix">
                    <button type="button" class="width-25 pull-center btn btn-sm btn-primary" id="log_btn">
                        <i class="icon-key"></i>
                        立即注册
                    </button>
                </div>
                <div class="form-group">
                    <div class="col-sm-12"> 已有账号，赶快<a href="/" style="color: #00b7ee">登录</a>吧。</div>
                </div>
            </div>
        </form>
    </body>
    <script>
        //公司名非空验证
        function checkCompanyName() {
            var companyName = $("#companyName").val();
            if (companyName == null || companyName == "") {
                layer.tips('请输入企业名称!', '#companyName', {
                    tips: [2, 'red'],
                    time: 2000
                });
                return false;
            } else {
                $.post("/registExist", {
                    companyName: companyName,
                }, function (res) {
                    if (res.rs != true) {
                        layer.tips('企业名称已存在!', '#companyName', {
                            tips: [2, 'red'],
                            time: 2000
                        });
                        return false;
                    }
                })
                return true;
            }
        }

        //企业法人非空验证
        function checkCompanyLegalPerson() {
            var companyLegalPerson = $("#companyLegalPerson").val();
            var name = /^[\u4e00-\u9fa5]{2,4}$/;
            if (companyLegalPerson == null || companyLegalPerson == "") {
                layer.tips('请输入企业法人!', '#companyLegalPerson', {
                    tips: [2, 'red'],
                    time: 2000
                });
                return false;
            } else if (!name.test(companyLegalPerson)) {
                layer.tips('请输入正确的名字!', '#companyLegalPerson', {
                    tips: [2, 'red'],
                    time: 2000
                });
                return false;
            } else {
                return true;
            }
        }

        //企业账号非空验证
        function checkUseraccount() {
            var useraccount = $("#useraccount").val();
            if (useraccount == null || useraccount == "") {
                layer.tips('请输入企业账号!', '#useraccount', {
                    tips: [2, 'red'],
                    time: 2000
                });
                return false;
            } else {
                $.post("/registUser", {
                    useraccount: useraccount,
                }, function (res) {
                    if (res.rs != true) {
                        layer.tips('企业账号已存在!', '#useraccount', {
                            tips: [2, 'red'],
                            time: 2000
                        });
                        return false;
                    }
                })
                return true;
            }
        }

        //企业密码非空验证
        function checkpassword() {
            var userpwd = $("#userpwd").val();
            var reg = /^\w{6,16}$/
            if (userpwd == null || userpwd == "") {
                layer.tips('请输入登录密码!', '#userpwd', {
                    tips: [2, 'red'],
                    time: 2000
                });
                return false;
            } else if (!reg.test(userpwd)) {
                layer.tips('密码长度须为6-16位，由字母数字下划线组成!', '#userpwd', {
                    tips: [2, 'red'],
                    time: 2000
                });
                return false;
            } else {
                return true;
            }
        }

        //密码校验
        function checkPassword() {
            var password = $("#userpwd").val();
            var password1 = $("#password1").val();
            if (password != password1) {
                layer.tips('两次密码输入不相同!', '#password1', {
                    tips: [2, 'red'],
                    time: 2000
                });
                return false;
            } else {
                return true;
            }
        }

        //手机号校验
        function checkTel() {
            var tel = $("#companyTel").val();
            var reg_tel = /^[1][3,4,5,7,8][0-9]{9}$/;
            var flag = reg_tel.test(tel);
            if (tel == null || tel == "") {
                layer.tips('请输入手机号!', '#companyTel', {
                    tips: [2, 'red'],
                    time: 2000
                });
                return false;
            } else if (!flag) {
                layer.tips('手机号格式不正确!', '#companyTel', {
                    tips: [2, 'red'],
                    time: 2000
                });
                return false;
            } else {
                return true;
            }
        }

        //邮箱校验
        function checkEmail() {
            var companyEmail = $("#companyEmail").val();
            var reg_email = /^\w+@\w+\.\w+$/;
            var flag = reg_email.test(companyEmail);
            if (companyEmail == null || companyEmail == "") {
                layer.tips('请输入企业邮箱!', '#companyEmail', {
                    tips: [2, 'red'],
                    time: 2000
                });
                return false;
            } else if (!flag) {
                layer.tips('邮箱格式不正确!', '#companyEmail', {
                    tips: [2, 'red'],
                    time: 2000
                });
                return false;
            } else {
                $.post("/registEmail", {
                    companyEmail: companyEmail,
                }, function (res) {
                    if (res.rs != true) {
                        layer.tips('邮箱已存在!', '#companyEmail', {
                            tips: [2, 'red'],
                            time: 2000
                        });
                        return false;
                    }
                })
                return true;
            }
        }

        $(function () {
            $('#log_btn').on('click', function () {
                var v1 = $('#area').children(":eq(0)").val()
                var v2 = $('#area').children(":eq(1)").val();
                var v3 = $('#area').children(":eq(2)").val();

                var address = v1 + v2 + v3;
                $('#address').val(address);
                //接收表单数据
                var companyName = $("#companyName").val();
                var companyLegalPerson = $("#companyLegalPerson").val();
                var useraccount = $("#useraccount").val();
                var password = $("#userpwd").val();
                var password1 = $("#password1").val();
                var companyTel = $("#companyTel").val();
                var companyAddress = $("#address").val();
                var companyEmail = $("#companyEmail").val();
                var companyRange = $("#companyRange").val();
                if (checkCompanyName() && checkCompanyLegalPerson() && checkUseraccount() && checkpassword() && checkPassword() && checkTel() && checkEmail()) {
                    if (v1 == "-1" || v2 == "-1" || v3 == "-1") {
                        layer.tips('企业地址不能为空!', '#address1', {
                            tips: [2, 'red'],
                            time: 2000
                        });
                        return false;
                    }
                    if ($("#companyRange").val() == "-1") {
                        layer.tips('请选择经营范围!', '#companyRange', {
                            tips: [2, 'red'],
                            time: 2000
                        });
                        return false;
                    }
                    $("#log_btn").attr('disabled',true);
                    $.post("/register", {
                        companyName: companyName,
                        companyLegalPerson: companyLegalPerson,
                        userAccount: useraccount,
                        userPassword: password,
                        userPassword1: password1,
                        companyTel: companyTel,
                        companyAddress: companyAddress,
                        companyEmail: companyEmail,
                        companyRange: companyRange
                    }, function (res) {
                        if (res.rs) {
                            layer.msg('注册成功！', {icon: 1, time: 2000}, function () {
                                window.location.href = "/";
                            });
                        } else {
                            layer.alert('注册失败！', {
                                title: '提示框',
                                icon: 1,
                            });
                        }
                    })
                } else {
                    return false;
                }
            });
            //每一组件的离焦事件‘

        })


        //每一组件的离焦事件‘
        $("#companyName").blur(checkCompanyName);
        $("#companyLegalPerson").blur(checkCompanyLegalPerson);
        $("#useraccount").blur(checkUseraccount);
        $("#userpwd").blur(checkpassword);
        $("#password1").blur(checkPassword);
        $("#companyTel").blur(checkTel);
        $("#companyEmail").blur(checkEmail);

    </script>
</html>
<script src="/regiester/js/area.js"></script>
